package com.coocaa.ops.admin.base.validator;


import com.coocaa.ops.admin.base.language.CommonLanguageProperties;
import com.coocaa.ops.common.core.base.model.ResourceBaseModel;
import com.coocaa.ops.common.core.biz.dmp.entity.DmpRegistryRlsInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @author bijiahao
 * @date : 2018/6/7.
 * @description
 */
@Component
public class InputParamsValidator {
    private static CommonLanguageProperties commonLanguageProperties;

    public static boolean isDuplicateExist(Integer duplicateVersion) {
        return null != duplicateVersion && duplicateVersion > 0;
    }


    @Autowired
    public void setEnterKeyLetterArt(CommonLanguageProperties commonLanguageProperties) {
        InputParamsValidator.commonLanguageProperties = commonLanguageProperties;
    }

    /**
     * dmp内容是否有效-适用于资源ID已确定的,如: 版面 配置 dmp 板块
     *
     * @param id
     * @param entity
     * @return
     */
    public static boolean isDmpContentAvailable(Integer id, DmpRegistryRlsInfoEntity entity) {
        return null != id && null != entity && null != entity.getDmpPolicyId() && null != entity.getDmpCrowdId();
    }

    public static void validIdAndVersion(Integer id, Integer version) {
        Assert.notNull(id, commonLanguageProperties.getResourceId() + commonLanguageProperties.getNotNull());
        Assert.notNull(version, commonLanguageProperties.getResourceVersion() + commonLanguageProperties.getNotNull());
    }

    public static void validIdAndVersionAndType(ResourceBaseModel resourceBaseModel) {
        Assert.notNull(resourceBaseModel.getId(), commonLanguageProperties.getResourceId() + commonLanguageProperties.getNotNull());
        Assert.notNull(resourceBaseModel.getVersion(), commonLanguageProperties.getResourceVersion() + commonLanguageProperties.getNotNull());
        Assert.hasText(resourceBaseModel.getType(), commonLanguageProperties.getResourceType() + commonLanguageProperties.getNotNull());
    }

    public static void validIdAndVersionAndType(Integer id, Integer version, String type) {
        Assert.notNull(id, commonLanguageProperties.getResourceId() + commonLanguageProperties.getNotNull());
        Assert.notNull(version, commonLanguageProperties.getResourceVersion() + commonLanguageProperties.getNotNull());
        Assert.hasText(type, commonLanguageProperties.getResourceType() + commonLanguageProperties.getNotNull());
    }

    public static void validDmpContentAvailable(Integer id, DmpRegistryRlsInfoEntity entity, String msg) {
        Assert.notNull(id, msg);
        validDmpContentAvailable(entity);
    }

    public static void validDmpContentAvailable(DmpRegistryRlsInfoEntity entity) {
        Assert.notNull(entity, "dmpInfo" + commonLanguageProperties.getNotNull());
        Assert.notNull(entity.getDmpPolicyId(), "dmpPolicyId " + commonLanguageProperties.getNotNull());
        Assert.hasText(entity.getDmpPolicyName(), "dmpPolicyName " + commonLanguageProperties.getNotNull());
        Assert.notNull(entity.getDmpCrowdId(), "dmpCrowdId " + commonLanguageProperties.getNotNull());
        Assert.hasText(entity.getDmpCrowdName(), "dmpCrowdName " + commonLanguageProperties.getNotNull());
    }


    /**
     * dmp内容是否有效-适用于资源ID为确定的，如： 板块 配置 dmp 推荐位
     *
     * @param entity
     * @return
     */
    public static boolean isDmpContentAvailable(DmpRegistryRlsInfoEntity entity) {
        return null != entity && null != entity.getDmpPolicyId() && null != entity.getDmpCrowdId();
    }

    public static void validIdValue(Integer id) {
        Assert.notNull(id, commonLanguageProperties.getResourceId() + commonLanguageProperties.getNotNull());
    }

    public static void validIdsValue(Integer[] ids) {
        Assert.notEmpty(ids, commonLanguageProperties.getResourceId() + commonLanguageProperties.getNotNull());
    }

}
